/*
 * Project it.battlehorse.rcp.tools.log
 * Created on Nov 19, 2005
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * A copy of the LGPL is available also at
 * http://www.gnu.org/copyleft/lesser.html
 * 
 */
package it.battlehorse.rcp.tools.log.views;

import it.battlehorse.rcp.tools.commons.CommonsActivator;
import it.battlehorse.rcp.tools.log.ILoggable;

import java.util.Date;

import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.swt.graphics.Image;

/**
 * Label provider for the log table in {@link ActorLogView }
 * 
 * @author battlehorse
 * @since Nov 19, 2005
 */
public class ActorLogLabelProvider implements ITableLabelProvider {
	
	public Image getColumnImage(Object element, int columnIndex) {		
		ILoggable l = (ILoggable) element;
		if (columnIndex == ActorLogView.COLUMN_SEVERITY) {
			return CommonsActivator.getDefault().getImageRegistry().get(l.getSeverity().getImageKey());
		}
		else
			return null;
	}

	public String getColumnText(Object element, int columnIndex) {
		
		ILoggable l = (ILoggable) element;
		String message = null;
		
		switch (columnIndex) {
		
		case ActorLogView.COLUMN_SEVERITY :
			
			message = l.getSeverity().getMessage();									
			break;
			
		case ActorLogView.COLUMN_TIME :
							
			message = String.valueOf(new Date(l.getTime()));
			break;
			
		case ActorLogView.COLUMN_SOURCE : 
			message = l.getSource().toString();
			break;
			
		case ActorLogView.COLUMN_TYPE :
			
			message = l.getType().getMessage();
			break;
			
		case ActorLogView.COLUMN_MESSAGE : 
			
			message = l.getMessage();
			break;
		}
				
		return message;
	}

	public void addListener(ILabelProviderListener listener) {
		// Ignore, nothing to notify

	}

	public void dispose() {	}

	public boolean isLabelProperty(Object element, String property) {
		return false;
	}

	public void removeListener(ILabelProviderListener listener) {
		// Ignore, nothing to notify

	}

}
